<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加参赛项目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">参赛项目</label>
        <div class="layui-input-block">
            <input type="text" name="projectName" lay-verify="required" lay-reqtext="项目名不能为空" placeholder="请输入项目名" value="" class="layui-input">
            <!--<tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">项目介绍</label>
        <div class="layui-input-block">
            <input type="text" name="projectTro" lay-verify="required" lay-reqtext="介绍不能为空" placeholder="请输入介绍" value="" class="layui-input">

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">成绩/单位</label>
        <div class="layui-input-block">
            <input type="text" name="unit" lay-verify="required" lay-reqtext="成绩不能为空" placeholder="请输入成绩" value="" class="layui-input">

        </div>
    </div>

    <div class="layui-form-item" pane="">
        <label class="layui-form-label">性别限制</label>
        <div class="layui-input-block" id="gender" >
            <input type="radio" name="genderLimit" value="1" title="男" checked="">
            <input type="radio" name="genderLimit" value="0" title="女">
            <!--<input type="radio" name="sex" value="禁" title="禁用" disabled="">-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">参赛场所</label>
        <div class="layui-input-block">
            <input type="text" name="place" placeholder="请输入参赛场所" value="" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">比赛日期</label>
            <div class="layui-input-block">
                <input type="text" name="date" id="date1" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input type="text" name="startTime" class="layui-input" id="test2" placeholder="yyyy-MM-dd HH:mm:ss">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束日期</label>
            <div class="layui-input-inline">
                <input type="text" name="endTime" class="layui-input" id="test3" placeholder="yyyy-MM-dd HH:mm:ss">
            </div>
        </div>
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">状态</label>-->
            <!--<div class="layui-input-block">-->
                <!--&lt;!&ndash;<input type="checkbox" id="deleted" name="deleted"  value="" class="layui-input">&ndash;&gt;-->
                <!--<input type="checkbox" id="deleted" name="deleted" lay-skin="switch" lay-filter="filter" lay-text="已参赛完|未参赛完"-->
                       <!--lay-skin="switch">-->
            <!--</div>-->
        <!--</div>-->
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/utils.js"></script>
<script>
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,//日期
            $ = layui.$;


//日期时间选择器
        laydate.render({
            elem: '#date1'
        });

//         laydate.render({
//             elem: '#test1'
//
//             ,type: 'datetime'
//         });
        laydate.render({
            elem: '#test2'

            ,type: 'datetime'
        });
        laydate.render({
            elem: '#test3'

            ,type: 'datetime'
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {
                // 关闭弹出层
                layer.close(index);
                $.ajax({
                    type:"get",
                    url:"/sport/project/add",
                    data:data.field,
                    error:function () {
                        layer.alert("数据上传失败，请稍后重试");
                    },
                    success:function (data) {
                        console.log(data)
                        if (data.code == 0){
                                layer.alert(data.msg,{icon: 6},function () {
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                window.parent.location.reload();//成功后刷新父界面

                            });
                        } else{
                            layer.alert(data.msg, {icon: 6});
                        }
                    }
                });
                // var iframeIndex = parent.layer.getFrameIndex(window.name);
                // parent.layer.close(iframeIndex);
                //

            });

            return false;
        });

    });
</script>
</body>
</html>